package com.student.wym.mapper;

import com.student.wym.po.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentMapper {

    @Select("select count(*) from ks_student s where s.exam_id = #{id}")
    Integer findStudentNum(Integer id);

    @Select("select * from ks_student s where s.exam_id = #{examId}")
    List<Student> findAllByExamId(int examId);

    void insertAll(List<Student> student);

    @Select("select * from ks_student")
    List<Student> findAll();

    @Delete("delete from ks_student")
    void deleteAll();

    @Insert("insert into ks_student(idx,exam_id,grade,department,major,name,student_no,school_no,exam_state,exam_score,make_up_state,make_up_score,state,exam_time,make_up_time,pass,againe,exam_name)"
            + "values(#{idx},#{examId},#{grade},#{department},#{major},#{name},#{studentNo},#{schoolNo},#{examState},#{examScore},#{makeUpState},#{makeUpScore},#{state},#{examTime},#{makeUpTime},#{pass},#{againe},#{examName})")
    void insert(Student student);

    @Select("select count(*) from ks_student ks where ks.exam_id=#{examId} and (ks.exam_state!=0 or ks.make_up_state!=0)")
    Integer findEd(Integer examId);

    @Select("select count(*) from ks_student ks where ks.exam_id=#{examId} and (ks.exam_state=2 or ks.make_up_state=2)")
    Integer findPass(Integer examId);

    @Select("select * from ks_student ks where ks.name = #{name}")
    Student findByName(String name);

    @Select("select * from ks_student ks where ks.id = #{studentId}")
    Student findByStudentId(Integer studentId);

    @Select("select ks.id from ks_student ks where ks.student_no = #{studentNo}")
    Integer findByStudentNo(String studentNo);

    @Select("select * from ks_student ks where ks.student_no = #{studentNo}")
    Student findOneByNo(String studentNo);

    @Select("select * from ks_student ks where ks.name = #{studentName}")
    List<Student> findOneByName(String studentName);

}
